package com.yjq.blog.article.controller;

import com.yjq.blog.article.entity.Article;
import com.yjq.blog.article.service.ArticleService;
import com.yjq.blog.article.vo.ArticleAddVO;
import com.yjq.blog.article.vo.ArticleListResponseVO;
import com.yjq.blog.article.vo.ArticleSearchVO;
import com.yjq.blog.article.vo.ArticleUpdateVO;
import com.yjq.blog.utils.Page;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;

@RestController
@RequestMapping("/article")
public class ArticleController {

    @Resource
    private ArticleService articleService;

    @GetMapping
    public Page<ArticleListResponseVO> pageArticle (ArticleSearchVO searchVO,
                                                    @RequestParam(defaultValue = "1") Integer pageNo,
                                                    @RequestParam(defaultValue = "10") Integer pageSize) {
        return articleService.pageArticle(searchVO, pageNo, pageSize);
    }

    @GetMapping("/{id}")
    public ArticleAddVO getArticleById(@PathVariable("id") Integer id) {
        return articleService.getArticleById(id);
    }

    @PostMapping
    public Boolean addArticle(@RequestBody ArticleAddVO articleVO) {

        Integer userId = 1;

        return articleService.addArticle(articleVO, userId);
    }

    @PutMapping
    public Boolean updateArticle(@RequestBody ArticleUpdateVO articleVO) {

        Integer userId = 1;

        return articleService.updateArticle(articleVO, userId);
    }
}
